import { resolve } from 'path'
import { defineConfig } from 'vite'
import viteCompression from 'vite-plugin-compression';
import Vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '~': resolve(__dirname, 'src'),
      '@/src': resolve(__dirname, 'src'),
      '@/api': resolve(__dirname, 'src/api'),
      '@/assets': resolve(__dirname, 'src/assets'),
      '@/common': resolve(__dirname, 'src/common'),
      '@/components': resolve(__dirname, 'src/components'),
      '@/composables': resolve(__dirname, 'src/composables'),
      '@/directive': resolve(__dirname, 'src/directive'),
      '@/i18n': resolve(__dirname, 'src/i18n'),
      '@/layout': resolve(__dirname, 'src/layout'),
      '@/plugins': resolve(__dirname, 'src/plugins'),
      '@/router': resolve(__dirname, 'src/router'),
      '@/store': resolve(__dirname, 'src/store'),
      '@/styles': resolve(__dirname, 'src/styles'),
      '@/utils': resolve(__dirname, 'src/utils'),
      '@/view': resolve(__dirname, 'src/view'),
    }
  },
  // css: {
  //   preprocessorOptions: {
  //     scss: {
  //       additionalData: `@import "@/styles/index.scss";`
  //     }
  //   }
  // },
  plugins: [
    Vue(),
    viteCompression({
      threshold: 1024000 // 对大于 1mb 的文件进行压缩
    })
  ],
  server: {
    port: 8182,
    host: true,
    open: true,
    proxy: {
      '/api': {
        target: 'http://10.32.224.22:8860', // 代理地址
        changeOrigin: true, // 开启代理
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
